<template>
  <div>
    <ul>
      <li v-for="item in messageList" :key="item.id">
        <!-- 跳转路由并且携带params参数，to的字符串写法 -->
        <!-- <router-link
          active-class="active"
          :to="`/Home/Message/Detail/${item.id}/${item.title}/`"
          >{{ item.title }}</router-link
        > -->
        <!-- 跳转路由并且携带params参数，to的对象写法,这里需要些name，query需要的是path -->
        <router-link
          active-class="active"
          :to="{
            name: 'detail',
            query: {
              id: item.id,
              title: item.title,
            },
          }"
          >{{ item.title }}</router-link
        >
        <button @click="pushShow(item)">push查看</button>
        <button @click="replaceShow(item)">replace查看</button>
      </li>
    </ul>
    <hr />
    <router-view> </router-view>
  </div>
</template>

<script>
export default {
  name: "Message",
  data() {
    return {
      messageList: [
        { id: "001", title: "消息001" },
        { id: "002", title: "消息002" },
        { id: "003", title: "消息003" },
      ],
    };
  },
  beforeDestroy() {
    console.log('组件即将被销毁',  this);
  },
  methods: {
    pushShow(item) {
      this.$router.push({
        name: "detail",
        query: {
          id: item.id,
          title: item.title,
        }
      })
    },
    replaceShow(item){
				this.$router.replace({
					name:'detail',
					query:{
						id:item.id,
						title:item.title
					}
				})
			}
  },
};
</script>

<style scoped>
hr {
  margin-top: 20px;
  margin-bottom: 20px;
  border: 0;
  border-top: 1px solid #a70b0b;
}
</style>